package com.hae.cloud.testuserservicezk.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping
public class UserController {

    @Value("${server.port}")
    private String port;

    @RequestMapping("/getUser")
    public String getUser() {
        return "this is getMember" + port;
    }

    @Autowired
    private DiscoveryClient discoveryClient;

    /**
     * 获取注册中心上某个服务的信息
     * @return
     */
    @RequestMapping("/getService")
    public List<ServiceInstance>  getService() {
        List<ServiceInstance> instanceList = discoveryClient.getInstances("zk-member");
        for (ServiceInstance serviceInstance: instanceList
             ) {
            System.out.println("url:"+ serviceInstance.getUri());
        }
        return instanceList;

    }
}
